<template>
    <a-spin :spinning="confirmLoading">
        <j-form-container :disabled="formDisabled">
            <!-- 主表单区域 -->
            <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
                <a-row>
                    <a-col :span="8">
                        <a-form-model-item label="预定类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bookType">
                            <j-dict-select-tag type="list" v-model="model.bookType" dictCode="book_type"
                                placeholder="请输入预定类型(散客/团体)" />
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="8">
                        <a-form-model-item label="预定人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bookPerson">
                            <a-input v-model="model.bookPerson" placeholder="请输入预定人"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="8">
                        <a-form-model-item label="预定时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bookDate">
                            <j-date v-model="model.bookDate" :showTime="true" dateFormat="YYYY-MM-DD HH:mm:ss"
                                style="width: 100%;" />
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <a-col :span="8">
                        <a-form-model-item label="联系电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="photo">
                            <a-input v-model="model.photo" placeholder="请输入联系电话"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="8">
                        <a-form-model-item label="客户单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="company">
                            <a-input v-model="model.company" placeholder="请输入客户单位"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="8">
                        <a-form-model-item label="优惠理由" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="discountReason">
                            <a-input v-model="model.discountReason" placeholder="请输入优惠理由"></a-input>
                        </a-form-model-item>
                    </a-col>
                </a-row>
                <a-row>
                    <!-- <a-col :span="8">
                        <a-form-model-item label="预订状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bookStatus">
                            <a-input v-model="model.bookStatus" placeholder="请输入预订状态"></a-input>
                        </a-form-model-item>
                    </a-col> -->
                    <a-col :span="8">
                        <a-form-model-item label="账户类型(vip)" :labelCol="labelCol" :wrapperCol="wrapperCol"
                            prop="accountType">
                            <j-dict-select-tag type="list" v-model="model.accountType" dictCode="account_type"
                                placeholder="请请输入账户类型(vip)" />
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="8">
                        <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
                            <a-input v-model="model.remark" placeholder="请输入备注"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="8">
                        <a-form-model-item label="预订单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
                            <a-input v-model="model.bookCode" placeholder="系统自动生成" disabled></a-input>
                        </a-form-model-item>
                    </a-col>
                </a-row>
            </a-form-model>
        </j-form-container>
        <!-- 子表单区域 -->
        <a-tabs type="card" v-model="activeKey">
            <a-tab-pane tab="预订单明细信息" key="yudingmingxi">
                <YuDingMingXiList :yudingdan="model" v-if="activeKey === 'yudingmingxi'" :disabled="formDisabled" />
            </a-tab-pane>
            <a-tab-pane tab="预订单收款管理" key="yudingshoukuan">
                <YuDingShouKuanList :yudingdan="model" v-if="activeKey === 'yudingshoukuan'" :disabled="formDisabled" />
            </a-tab-pane>
        </a-tabs>
    </a-spin>
</template>
  
<script>
import { httpAction, getAction } from '@/api/manage'
import JFormContainer from '@/components/jeecg/JFormContainer'
import dayjs from 'dayjs'
import YuDingMingXiList from '../../YuDingMingXi/YuDingMingXiList'
import YuDingShouKuanList from '../../YuDingShouKuan/YuDingShouKuanList'

export default {
    name: 'YuDingGuanLiForm',
    components: {
        JFormContainer,
        YuDingMingXiList,
        YuDingShouKuanList
    },
    data() {
        return {
            labelCol: {
                xs: { span: 24 },
                sm: { span: 6 },
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 },
            },
            model: {
                bookDate: dayjs().format('YYYY-MM-DD HH-mm-ss'),
            },
            confirmLoading: false,
            // 新增时子表默认添加几行空数据
            addDefaultRowNum: 0,
            validatorRules: {
                bookType: [{ required: true, message: '请完善内容' }],
                bookPerson: [{ required: true, message: '请完善内容' }],
                bookDate: [{ required: true, message: '请完善内容' }],
                photo: [{ required: true, message: '请完善内容' }],
            },
            activeKey: 'yudingmingxi',
            url: {
                add: "/room/roomBookInfo/add",
                edit: "/room/roomBookInfo/edit",
                queryById: "/room/roomBookInfo/queryById",
            },
        }
    },
    props: {
        //表单禁用
        disabled: {
            type: Boolean,
            default: false,
            required: false
        }
    },
    computed: {
        formDisabled() {
            return this.disabled
        },
    },
    created() {
        //备份model原始值
        this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
        add() {
            this.edit(this.modelDefault);
        },
        edit(record) {
            if (record.roomLevelCode) {
                this.disableCode = true
            }
            this.model = Object.assign({}, record);
            this.visible = true;
        },
        submitForm() {
            const that = this;
            // 触发表单验证
            this.$refs.form.validate(valid => {
                if (valid) {
                    that.confirmLoading = true;
                    let httpurl = '';
                    let method = '';
                    if (!this.model.id) {
                        httpurl += this.url.add;
                        method = 'post';
                    } else {
                        httpurl += this.url.edit;
                        method = 'put';
                    }
                    httpAction(httpurl, this.model, method).then((res) => {
                        if (res.success) {
                            that.$message.success(res.message);
                            that.$emit('ok');
                        } else {
                            that.$message.warning(res.message);
                        }
                    }).finally(() => {
                        that.confirmLoading = false;
                    })
                }

            })
        },
    }
}
</script>
  
<style scoped></style>